/**
 * 
 */
package com.service.impl;

import java.util.List;
import java.util.UUID;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.entity.Student;
import com.entity.StudentExample;
import com.entity.StudentExample.Criteria;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.StudentMapper;
import com.service.StudentService;
/**
 *@name    中文名称
 *@description spring事务注解
 *@time    创建时间:2020年2月25日下午4:33:58
 *@return
 *@author   张孜
 *@history 修订历史（历次修订内容、修订人、修订时间等）
 */
@Service
@Transactional(rollbackFor   =  Exception.class)
public class StudentServiceImpl implements StudentService{
@Autowired
StudentMapper mapper;
    @Override
    public PageInfo<Student> getAllStudents(int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        StudentExample example=new StudentExample();
        example.setOrderByClause("Sage");
		List<Student> studentList=mapper.selectByExample(example);
        PageInfo<Student>  studentPageInfo = new PageInfo<>(studentList);
       return studentPageInfo;
    }
    @Override
    public String saveStudents(Student student) {
		 	String sid = student.getSid();
	        //新增
	        if (sid==null||sid=="") {
	        	 //生成id
			       sid = UUID.randomUUID().toString().replace("-", "");
			       student.setSid(sid);
	        	mapper.insertSelective(student);
	        	throw new RuntimeException("发生异常"); 
	        }else {
	           StudentExample example=new StudentExample();
	           Criteria createCriteria = example.createCriteria();
	           createCriteria.andSidEqualTo(sid);
	           mapper.updateByExample(student, example);
	        }
	        
			return sid;
	}
}
